package com.bw1806.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bw1806.mapper.TbItemMapper;
import com.bw1806.pojo.TbItem;
import com.bw1806.pojo.TbItemExample;
import com.bw1806.sellergoods.service.TbItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @描述
 * @创建人 wangyue
 * @创建时间2020/11/1115:02
 */
@Service(timeout = 5000,retries = 0)
public class TbItemServiceImpl implements TbItemService {

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public List<TbItem> findAll() {
        return tbItemMapper.selectByExample(null);
    }

    @Override
    public PageResult<TbItem> pagelist(TbItem tbItem,int pageNum,int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        TbItemExample example=new TbItemExample();

        TbItemExample.Criteria criteria = example.createCriteria();

        if(tbItem!=null){
            //if(tbItem.getName()!=null && tbItem.getName().length()>0){
            //    criteria.andNameLike("%"+tbItem.getName()+"%");
           // }
        }

        Page<TbItem> page= (Page<TbItem>) tbItemMapper.selectByExample(example);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void save(TbItem tbItem) {
        Long id = tbItem.getId();
        if(id != null && id !=0){
            tbItemMapper.updateByPrimaryKey(tbItem);
        } else{
            tbItemMapper.insert(tbItem);
        }
    }

    @Override
    public TbItem getById(Long id) {
        return tbItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deletebth(Long[] ids) {
       for(long id : ids){
            tbItemMapper.deleteByPrimaryKey(id);
        }
        //tbItemMapper.deletebth(ids);
    }
}
